package com.crk.yiyuanguahao.controller;

import com.crk.yiyuanguahao.entity.User;
import com.crk.yiyuanguahao.entity.UserRemark;
import com.crk.yiyuanguahao.service.UserRemarkService;
import com.crk.yiyuanguahao.util.LayUiTableJson;
import com.crk.yiyuanguahao.util.Page;
import com.crk.yiyuanguahao.util.ResponseResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author
 * @description:
 * @date 2020/3/26
 */
@RestController
@RequestMapping("userRemark")
public class UserRemarkController {
    @Autowired
    UserRemarkService userRemarkService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/userRemark/userRemarkList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/userRemark/userRemarkAdd.html");
        return modelAndView;
    }

    @GetMapping("edit")
    public ModelAndView edit(){

        ModelAndView modelAndView = new ModelAndView("/workspace/userRemark/userRemarkEdit.html");
        return modelAndView;
    }

    @RequestMapping("detailInfo")
    public ModelAndView detailInfo(){
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        if (user.getUserType() == 1){
            ModelAndView modelAndView = new ModelAndView("/workspace/userRemark/userRemarkDetailInfo.html");
            return modelAndView;
        }else{
            ModelAndView modelAndView = new ModelAndView("/workspace/userRemark/userRemarkDetailInfo1.html");
            return modelAndView;
        }

    }

    @RequestMapping("saveUserRemark")
    public ResponseResult saveUserRemark(UserRemark userRemark){
        return userRemarkService.saveUserRemark(userRemark);
    }

    @RequestMapping("deleteUserRemark")
    public ResponseResult deleteUserRemark(@RequestParam("id") Integer id){
        return userRemarkService.deleteUserRemark(id);
    }

    @RequestMapping("getUserRemark")
    public ResponseResult getUserRemark(@RequestParam("id") Integer id){
        return userRemarkService.getUserRemark(id);
    }

    @RequestMapping("queryUserRemarkPage")
    public LayUiTableJson queryUserRemarkPage(int status
            , @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = userRemarkService.queryUserRemarkPage(status,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("approval")
    public ResponseResult approval(@RequestParam("id") Integer id,@RequestParam("status") int status){
        return userRemarkService.approval(id,status);
    }

    /**
     * 查询最新留言
     * @return
     */
    @RequestMapping("queryLastUserRemark")
    public ResponseResult queryLastUserRemark(){
        return userRemarkService.queryLastUserRemark();
    }


    @RequestMapping("getDetailInfo")
    public ResponseResult getDetailInfo(@RequestParam("id") Integer id){
        return userRemarkService.getDetailInfo(id);
    }

    @RequestMapping("saveReplay")
    public ResponseResult saveReplay(@RequestParam("id") Integer id,@RequestParam("replay") String replay){
        return userRemarkService.saveReplay(id,replay);
    }
}
